package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelQuestion;
import cn.wolfcode.trip.base.domain.VisaManager;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelQuestionQuery;
import cn.wolfcode.trip.base.service.ITravelQuestionService;
import cn.wolfcode.trip.base.service.IVisaService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("visas")
public class VisaController {

    @Autowired
    private IVisaService visaService;

    @GetMapping
    public Object list(QueryObject qo){
        PageInfo pageInfo = visaService.selectForListPrice(qo);
        return pageInfo;
    }

    @GetMapping("/{visaCountryId}")
    public Object list(@PathVariable Long visaCountryId){
        return visaService.list(visaCountryId);
    }

    @PostMapping("save")
    public JSONResult save(VisaManager visaManager) {
        JSONResult result = new JSONResult();
        try {
            visaService.save(visaManager);
        }catch (Exception e){
            result.mark(e.getMessage());
        }
        return result;
    }

    @GetMapping("/country/{state}")
    public Object list(@PathVariable int state){
        return visaService.getCountrysByState(state);
    }

}
